/**
 * Created by liubin on 2017/6/2.
 */


var DtjCard = cc.Sprite.extend({

    mCardNum : null,
    mSelected : null,
    mNumSpr : null,

    ctor : function() {
        this._super();

        this.setSpriteFrame("card_back.png");

        this.setScale(mo.dtjCardHelper.cardScale);
        this.setAnchorPoint(cc.p(0.5, 0.5));

        this.mNumSpr = new cc.Sprite();
        this.mNumSpr.setVisible(false);
        this.mNumSpr.setPosition(cc.p(60 * 0.5 - 3, 133 * 0.5));
        this.addChild(this.mNumSpr);

        this.mCardNum = 0;
        this.mSelected = false;
    },

    setCardSprite : function (num) {
        this.mNumSpr.setVisible(true);
        this.mNumSpr.setSpriteFrame("card"+num+".png");
    },

    setCardNum : function(num){
        if (mo.dtjCardHelper.getExistCardNum(num)){
            this.mCardNum = num;
        }else{
            this.mCardNum = 0;
            this.mNumSpr.setVisible(false);
        }
    },

    setDtjCardRotation : function (rotation) {
        if(rotation == 90){
            this.setSpriteFrame("card_back_1.png");
            this.mNumSpr.setPosition(cc.p(60 * 0.5 + 3, 133 * 0.5));
        }
        this.setRotation(rotation);
    },

    //翻牌
    fanpai : function () {
        if(this.mCardNum == 0){
            return;
        }

        if(this.mNumSpr.isVisible()){
            return;
        }

        var scale = this.getScale();

        this.stopAllActions();
        this.runAction(cc.sequence(
            cc.scaleTo(0.2, 0, scale),
            cc.callFunc(function(){
                this.setCardSprite(this.mCardNum);
            }, this),
            cc.scaleTo(0.2, scale, scale)
        ));
    },

});